package com.material.vtool.controller;

import com.google.common.collect.Maps;
import com.material.vtool.entity.combinedEntity.SlideshowEntity;
import com.material.vtool.entity.respEntity.RespData;
import com.material.vtool.entity.respEntity.ReturnCode;
import com.material.vtool.service.SlideshowInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/slideshow")
public class SlideshowInfoController {
    @Autowired
    private SlideshowInfoService slideshowInfoService;

    /**
     * 获取小程序的轮播图列表
     * @param miniCode 小程序标识
     * @return
     */
    @GetMapping(value = "/list", produces = "application/json;charset=UTF-8")
    public RespData list(@RequestHeader("miniCode") String miniCode) {
        if (StringUtils.isBlank(miniCode)) {
            RespData respData = new RespData();
            respData.setCode(ReturnCode.CLIENT_ERROR);
            respData.setMsg("参数异常");
            return respData;
        }
        List<SlideshowEntity> slideshowList = slideshowInfoService.getSlideshowList(miniCode);

        HashMap<String, Object> resultMap = Maps.newHashMapWithExpectedSize(10);
        resultMap.put("slideshowList", slideshowList);

        RespData respData = new RespData();
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("成功");
        respData.setData(resultMap);
        return respData;
    }
}
